package org.clockworkmages.games.anno1186.situations.gameoptions.options;

import java.util.Calendar;

import org.clockworkmages.games.anno1186.GameBeansContext;
import org.clockworkmages.games.anno1186.GameDataService;
import org.clockworkmages.games.anno1186.GameState;
import org.clockworkmages.games.anno1186.GameStateService;
import org.clockworkmages.games.anno1186.GameTimeService;
import org.clockworkmages.games.anno1186.model.option.Option;
import org.clockworkmages.games.anno1186.model.situation.Situation;

public class NewGameOption
		extends Option {
	private GameDataService gameDataService;
	private GameStateService gameStateService;
	private GameTimeService gameTimeService;

	public NewGameOption() {
		gameDataService = GameBeansContext.getBean(GameDataService.class);
		gameStateService = GameBeansContext.getBean(GameStateService.class);
		gameTimeService = GameBeansContext.getBean(GameTimeService.class);
		setLabel("New Game");
	}

	@Override
	public void select() {
		Calendar calendar = Calendar.getInstance();
		calendar.set(1492, Calendar.AUGUST, 2, 22, 16);

		GameState gameState = new GameState();
		gameState.setTime(calendar.getTimeInMillis());

		gameStateService.setGameState(gameState);
		gameTimeService.advanceTime(1L);

		String startSituationId = gameDataService.getGameData()
				.getGameStartSituation();
		Situation startSituation = gameDataService.getGameData()
				.getSituations().get(startSituationId);
		gameStateService.addSituation(startSituation, true);

		super.select();
	}
}
